﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalFight.Lib.Interfaces;
using AnimalFight.Lib.EventHandlers;

namespace AnimalFight.Lib.Data
{
    public class Duck : AnimalBase, IAttack, IAttackable
    {
        public event AttackDelegate AttackEvent;

        public void Attack(string targetName)
        {
            if (AttackEvent != null)
            {
                AttackEventHandler eventHandler = new AttackEventHandler
                {
                    AnimalName = targetName,
                    AP = this.AP
                };

                AttackEvent(this, eventHandler);
            }
        }

        public override void Escape()
        {
            this.HasEscaped = true;
            System.Console.WriteLine("Duck has escaped.");
        }

        public void Attacked(int ap)
        {
            if (this._hasEscaped)
            {
                Console.WriteLine("{0} has escaped. Cannot be attacked.", this.Name);
            }
            else if (this._isDead)
            {
                Console.WriteLine("{0} has already dead. Cannot be attacked.", this.Name);
            }
            else
            {
                Console.WriteLine("{0} has been attacked. Current HP = {1}", this.Name, this.HP);

                this.HP -= (ap - this.DP);

                Console.WriteLine("HP is decreased -{1}", this.Name, ap - this.DP);
                Console.WriteLine("Current HP = {0}", this.HP);

                if (this.HP <= 0)
                {
                    this.IsDead = true;
                }
            }
        }
    }
}
